# coding = utf-8
import datetime

from rest_framework.viewsets import ModelViewSet

from polls.api.serializers import WxQuestionSerializer
from polls.models import Question
from wxchat.api.permissions import WeixinPermission


class WxQuestionViewSet(ModelViewSet):
    authentication_classes = ()
    permission_classes = (WeixinPermission,)
    queryset = Question.objects.filter(flag=1)
    serializer_class = WxQuestionSerializer
    http_method_names = ['get', 'put']

    def get_queryset(self):
        queryset = super().get_queryset()

        cur_date = datetime.datetime.now().date()

        queryset = queryset.filter(begin_date__lte=cur_date, end_date__gte=cur_date)

        return queryset

